﻿Module ReadXML
    ' ReadXML Class. Many Thanks to Travis Stubley for making this work :)

    Public Function Read(ByVal File As String, ByVal MainElement As String, ByVal ChildElement As String) As String
        '
        ' Verify the configuration file exists.
        '
        Dim aConfigPath As String = File
        Dim data As String = String.Empty
        If Not System.IO.File.Exists(aConfigPath) Then
            Return False
        End If
        '
        ' Read the data
        '
        Dim xmlDoc As New Xml.XmlDocument
        Dim xmlNode As Xml.XmlNode
        Dim xmlNodeR As Xml.XmlNode
        Dim xmlFound As Boolean = False
        xmlDoc.Load(aConfigPath)
        xmlNode = xmlDoc.DocumentElement.SelectSingleNode(MainElement)
        xmlNodeR = xmlNode.SelectSingleNode(ChildElement)
        data = xmlNodeR.InnerText
        If data <> "" Then
            Return data
        Else
            Return "Value does not exist"
        End If
    End Function

    Public Function Modify(ByVal File As String, ByVal MainElement As String, ByVal ChildElement As String, ByVal Value As String)
        '
        ' Verify the configuration file exists.
        '
        Dim aConfigPath As String = File
        Dim data As String = String.Empty
        If Not System.IO.File.Exists(aConfigPath) Then
            Return False
        End If
        '
        ' Modify the data
        '
        Dim xmlDoc As New Xml.XmlDocument
        Dim xmlNode As Xml.XmlNode
        Dim xmlNodeR As Xml.XmlNode
        Dim xmlFound As Boolean = False
        xmlDoc.Load(aConfigPath)
        xmlNode = xmlDoc.DocumentElement.SelectSingleNode(MainElement)
        xmlNodeR = xmlNode.SelectSingleNode(ChildElement)
        xmlNodeR.InnerText = Value
        xmlDoc.Save(File)
    End Function
End Module